/**************************************************************

This do file creates the main tables and Figures in Abarcar and Theoharides

**************************************************************/
capture log close
capture program drop _all
capture macro drop _all
estimates drop _all
set matsize 2000
drop _all
set more off


*UPDATE PATH NAMES;
global ched_data 
global output 
global figures

***************************************************************

log using "${figures}analysis.log", replace 

**********************************************************************;
*FIGURE 1;
**********************************************************************;
#delimit ;
use "${ched_data}analysis_sample.dta", clear ;

*Panel a;
keep if year>=1990&year<=2014;

gen othernurse=nurse-nurseUSA;

collapse (sum) nurseUSA othernurse nonnurse, by(year);

replace nonnurse=nonnurse/1000;
replace othernurse=othernurse/1000;
replace nurseUSA=nurseUSA/1000;

twoway (scatter nurseUSA year, connect(1) lcolor(black) msymbol(circle) mcolor(black))
	   (line othernurse year, lcolor(black) lpattern(dot))
	   (line nonnurse year, yaxis(2) lcolor(black) lpattern(dash)), 
	   ytitle("Nurse Migrants (1,000s)") ytitle("Non-nurse Migrants (1,000s)", axis(2))
	   ylabel(0(10)60, axis(2)) legend(off)
	   plotregion(fcolor(white)) graphregion(fcolor(white))
	   	xline(2000 2007, lpattern(solid) lcolor(gs14))
	ylab(, nogrid);

graph export "${figures}Main Figures/Figure1a.pdf", replace;

*Panel b;
use "${ched_data_clean}enrolltable_nursing.dta", clear;

forvalues x=1990/2013 {;
	replace emftotal`x'=emftotal`x'/1000;
};

*Categories;
gen agg_group="Nursing" if pscedgroup=="100";
replace agg_group="Business" if pscedgroup=="34"|pscedgroup=="30";
replace agg_group="Humanities" if pscedgroup=="0"|pscedgroup=="18"|pscedgroup=="22"|pscedgroup=="26"|pscedgroup=="38";
replace agg_group="Education" if pscedgroup=="14";
replace agg_group="STEM" if pscedgroup=="42"|pscedgroup=="46"|pscedgroup=="50"|pscedgroup=="54";
replace agg_group="Other" if pscedgroup=="89"|pscedgroup=="52"|pscedgroup=="58"|pscedgroup=="62"|pscedgroup=="66"|pscedgroup=="78"|pscedgroup=="84";

collapse (sum) emftotal*, by(agg_group);
sort agg_group;
egen agg_num=group(agg_group);

reshape long emftotal, i(agg_num) j(year); 
drop agg_group; 
reshape wide emftotal, i(year) j(agg_num);

/*
Business:  1
Education: 2
Humanities: 3
Nursing: 4
Other: 5
STEM: 6
*/

twoway (scatter emftotal4 year, connect(1) lcolor(black) msymbol(circle) mcolor(black)) 
		(line emftotal1 year, lcolor(gs8))
		(line emftotal2 year, lcolor(black) lpattern(dash))
		(line emftotal3 year, lcolor(black) lpattern(dot))
		(line emftotal5 year, lcolor(black) lpattern(shortdash))
		(line emftotal6 year, lcolor(gs8) lpattern(dash)), 
	xline(2000 2007, lpattern(solid) lcolor(gs14))
	ytitle("Number of students enrolled (1,000s)")
	legend(off) xtitle("Year")
	plotregion(fcolor(white)) graphregion(fcolor(white))
	ylab(, nogrid);
	
graph export "${figures}Main Figures/Figure1b.pdf", replace;

*Figure 1c;
use "${ched_data_clean}gradtable_nursing.dta", clear;

forvalues x=1990/2013 {;
	replace gmftotal`x'=gmftotal`x'/1000;
};

*Categories;
gen agg_group="Nursing" if pscedgroup=="100";
replace agg_group="Business" if pscedgroup=="34"|pscedgroup=="30";
replace agg_group="Humanities" if pscedgroup=="0"|pscedgroup=="18"|pscedgroup=="22"|pscedgroup=="26"|pscedgroup=="38";
replace agg_group="Education" if pscedgroup=="14";
replace agg_group="STEM" if pscedgroup=="42"|pscedgroup=="46"|pscedgroup=="50"|pscedgroup=="54";
replace agg_group="Other" if pscedgroup=="89"|pscedgroup=="52"|pscedgroup=="58"|pscedgroup=="62"|pscedgroup=="66"|pscedgroup=="78"|pscedgroup=="84";

collapse (sum) gmftotal*, by(agg_group);
sort agg_group;
egen agg_num=group(agg_group);

reshape long gmftotal, i(agg_num) j(year); 
drop agg_group; 
reshape wide gmftotal, i(year) j(agg_num);

/*
Business:  1
Education: 2
Humanities: 3
Nursing: 4
Other: 5
STEM: 6
*/

keep if year>=1998;

egen gmftotal_all=rowtotal(gmftotal1 gmftotal2 gmftotal3 gmftotal4 gmftotal5 gmftotal6);

twoway (scatter gmftotal4 year, connect(1) lcolor(black) msymbol(circle) mcolor(black)) 
		(line gmftotal1 year, lcolor(gs8))
		(line gmftotal2 year, lcolor(black) lpattern(dash))
		(line gmftotal3 year, lcolor(black) lpattern(dot))
		(line gmftotal5 year, lcolor(black) lpattern(shortdash))
		(line gmftotal6 year, lcolor(gs8) lpattern(dash)), 
	xline(2000 2007, lpattern(solid) lcolor(gs14))
	ytitle("Number of graduates (1,000s)")
	legend(off) xtitle("Year")
	plotregion(fcolor(white)) graphregion(fcolor(white))
	ylab(, nogrid)
	xlabel(1990(5)2015);
	
graph export "${figures}Main Figures/Figure1c.pdf", replace;

*****************************************************************************;
*BEGIN MAIN ANALYSIS;

use "${ched_data}analysis_sample.dta", clear ;

xtset provcode year;

*SET CONTROLS;
global controls_yr emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr*;
global controls_yr_full emp_f_2564_90_yr* emp_m_2564_90_yr* female_90_yr* age_90_yr* nurse_cen_pc90_yr* _yrschl_2564_90_yr* urban_90_yr* ; 

*Create additional variables;
gen pass_rate_grad=(passed/collegepop)*100;
replace pass_rate_grad=0 if examinees==.;
gen examinee_rate_grad=(examinees/collegepop)*100;
replace examinee_rate_grad=0 if examinees==.;

replace ttrend=ttrend-12; 
gen ttrend_high1=ttrend*high1;

gen post2000_high=post2000*high1;
gen post2000_trend=post2000_high*(ttrend-1);

gen post2007_high=post2007*high1;
gen post2007_trend=post2007_high*(ttrend-1);
replace post2007_trend=post2007_trend-7 if post2007_trend!=0; 

*2003 and 2010 as four years ahead;
gen ttrend_three=ttrend-3;
gen ttrend_three_high1=ttrend_three*high1;

gen post2003_high=post2003*high1;
gen post2003_trend_three=post2003_high*(ttrend_three-1);

gen post2010_high=post2010*high1;

gen post2010_trend_three=post2010_high*(ttrend_three-1);
replace post2010_trend_three=post2010_trend_three-7 if post2010_trend_three!=0; 

tab year, gen(yr); 

*******************************************************************************;
* Figures 2, 3, and 4;
*Tables 1 and 2;
*******************************************************************************;

#delimit ;

foreach var of varlist migrateUSA_hth enroll_tot1 
	nurseprog nurseprog_private nurseprog_public 
	enroll_tot0 enroll_tot grad_tot0 grad_tot {;
	
	if "`var'"=="migrateUSA_hth" {; local t="1"; };
	if "`var'"=="enroll_tot1" {; local t="2"; };
	if "`var'"=="nurseprog" {; local t="4"; };
	if "`var'"=="nurseprog_private" {; local t="5"; };
	if "`var'"=="nurseprog_public" {; local t="6"; };
	
	if "`var'"=="enroll_tot0" {; local t="7"; };
	if "`var'"=="enroll_tot" {; local t="8"; };
	if "`var'"=="grad_tot0" {; local t="9"; };
	if "`var'"=="grad_tot" {; local t="10"; };
	
	if "`var'"=="migrateUSA_hth" {; local v="ylabel(-4(2)10) ymtick(-4(1)10)"; };
	if "`var'"=="enroll_tot1" {; local v="ylabel(-5(2)5) ymtick(-5(1)5)"; };
	if "`var'"=="enroll_tot0" {; local v="ylabel(-10(2)10) ymtick(-10(1)10)"; };
	if "`var'"=="enroll_tot" {; local v="ylabel(-10(2)10) ymtick(-10(1)10)"; };
	if "`var'"=="nurseprog" {; local v="ylabel(-1(2)5) ymtick(-1(1)5)"; };
	if "`var'"=="nonnurseprog" {; local v="ylabel(-6(2)11) ymtick(-6(1)10)"; };
	if "`var'"=="nurseprog_private" {; local v="ylabel(-1(2)5) ymtick(-1(1)5)"; };
	if "`var'"=="nurseprog_public" {; local v="ylabel(-1(2)5) ymtick(-1(1)5)"; };
	if "`var'"=="pass_rate" {; local v="ylabel(-5(2)5) ymtick(-5(1)5)"; };
	if "`var'"=="migrate_nonnurse" {; local v="ylabel(-0.05(.01).05) ymtick(-0.05(.005).05)"; };
	if "`var'"=="migrate_nonUSnurse" {; local v="ylabel(-0.05(.01).05) ymtick(-0.05(.005).05)"; };
	if "`var'"=="migrate_othernurse" {; local v="ylabel(-0.01(.01).01) ymtick(-0.01(.001).01)"; };
	if "`var'"=="nursedeg_nurse92" {; local v="ylabel(-10(20)50) ymtick(-10(10)50)"; };
	if "`var'"=="grad_tot0" {; local v="ylabel(-2(1)3) ymtick(-2(1)3)"; };
	if "`var'"=="grad_tot" {; local v="ylabel(-2(1)3) ymtick(-2(1)3)"; };
	if "`var'"=="pass_rate_grad" {; local v="ylabel(0(1)2) ymtick(0(0.5)2)"; };
	if "`var'"=="exp_med_wage" {; local v="ylabel(-10(5)20) ymtick(-10(5)20)"; };

	if "`var'"=="migrateUSA_hth" {; local w="1991"; };
	if "`var'"=="enroll_tot1" {; local w="1991"; };
	if "`var'"=="enroll_tot0" {; local w="1991"; };
	if "`var'"=="enroll_tot" {; local w="1991"; };
	if "`var'"=="nurseprog" {; local w="1991"; };
	if "`var'"=="nonnurseprog" {; local w="1991"; };
	if "`var'"=="nurseprog_private" {; local w="1991"; };
	if "`var'"=="nurseprog_public" {; local w="1991"; };
	if "`var'"=="pass_rate_pop" {; local w="1991"; };
	if "`var'"=="grad_tot0" {; local w="1998"; };
	if "`var'"=="grad_tot" {; local w="1998"; };
	if "`var'"=="pass_rate_grad" {; local w="1991"; };
	if "`var'"=="grad_tot0_nm" {; local w="1994"; };
	if "`var'"=="grad_tot_nm" {; local w="1994"; };
	if "`var'"=="exp_med_wage" {; local w="1991"; };

	if "`var'"=="migrateUSA_hth" {; local c="Nurse Migrants per 100000"; };
	if "`var'"=="enroll_tot1" {; local c="Percentage Points"; };
	if "`var'"=="enroll_tot0" {; local c="Percentage Points"; };
	if "`var'"=="enroll_tot" {; local c="Percentage Points"; };
	if "`var'"=="nurseprog" {; local c="Nursing Programs"; };
	if "`var'"=="nonnurseprog" {; local c="Number of Non-Nursing Programs"; };
	if "`var'"=="nurseprog_private" {; local c="Private Nursing Programs"; };
	if "`var'"=="nurseprog_public" {; local c="Public Nursing Programs"; };
	if "`var'"=="pass_rate" {; local c="Nursing Exam Pass Rate (%)"; };
	if "`var'"=="migrate_nonnurse" {; local c="Non-Nurse Migration"; };
	if "`var'"=="migrate_nonUSnurse" {; local c="Nurse Migration (Not US)"; };
	if "`var'"=="migrate_othernurse" {; local c="Nurse Migration (Not US)"; };
	if "`var'"=="nursedeg_nurse92" {; local c="Share with a Nursing (Medical) Degree Who Work in Medical Field"; };
	if "`var'"=="grad_tot0" {; local c="Percentage Points"; };
	if "`var'"=="grad_tot" {; local c="Percentage Points"; };
	if "`var'"=="pass_rate_grad" {; local c="Nursing Exam Pass Rate (%)"; };
	if "`var'"=="exp_med_wage" {; local c="Daily Wage (Pesos)"; };

	*POOLED;
	xi: reg `var' post2000_high post2000_trend post2007_high post2007_trend ttrend_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
		yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=`w'&year<=2013, cluster(province); 
	estimates store spec`t', title("`var'");
	su `var' if e(sample)&year<2000&high1==1;
	scalar dep_mean=r(mean);
	estadd scalar dep_mean=dep_mean;
	
	preserve;
	gen slope1991=-8*_b[ttrend_high1];
	forvalues x=1992/1998 {;
		local i=`x'-1999;
		gen slope`x'=`i'*_b[ttrend_high1];
	};

	gen slope1999=0*_b[ttrend_high1];

	forvalues x=2000/2006 {;
		local i=`x'-1999;
		local j=`x'-2000;

		gen slope`x'=`i'*_b[ttrend_high1]+_b[post2000_high]+`j'*_b[post2000_trend];
	};

	gen slope2007=8*_b[ttrend_high1]+_b[post2000_high]+7*_b[post2000_trend]+0*_b[post2007_trend]+_b[post2007_high];


	forvalues x=2008/2013 {;
		local i=`x'-1999;
		local j=`x'-2006;
		local k=`x'-2000;
		local m=`x'-2007;

		gen slope`x'=`i'*_b[ttrend_high1]+_b[post2000_high]+_b[post2007_high]+`k'*_b[post2000_trend]+`m'*_b[post2007_trend];

	};

	*EVENT STUDY;
	char year[omit]1999;
	xi: reg `var'  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , cluster(province) noomit;
	estimates store event`t', title("'var'");
	test _IyeaXhig_1992 _IyeaXhig_1993 _IyeaXhig_1994 _IyeaXhig_1995 _IyeaXhig_1996 _IyeaXhig_1997 _IyeaXhig_1998; 		
	scalar pretrend=r(p);
	estadd scalar pretrend=pretrend;
	sum `var' if high1==1 & year==2000;
	local mean=`r(mean)';
				
	foreach y of numlist 1991(1)1998 2000(1)2013 {;
			gen b_`y' = _b[_IyeaXhig_`y'];
			gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
			gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
	};

		gen b_1999=0;
		
		keep b_* upper_* lower_* slope*;
		
		
		collapse b_* upper_* lower_* slope*; 
		
		gen temp=1;
		reshape long b_ upper_ lower_ slope, i(temp) j(year); 
		drop temp;
		
		drop if year<`w';
		
		twoway (line b_ year, lcolor(black) lpattern(solid))
				(line upper_  year, lcolor(black) lpattern(dot))
				(line lower_ year, lcolor(black) lpattern(dot))
				(line slope year, lcolor(black) lpattern(dash)),

				legend(off)
				xtitle("Year") 
				yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle(`c')
				plotregion(fcolor(white)) graphregion(fcolor(white))
				xline(2000 2007, lpattern(solid) lcolor(gs14))
				`v';
				
		graph export "${figures}Main Figures/EventStudy_`var'.pdf", replace;

		
restore;	
};

******;
*Test 2003-2009 for graduation;
******;
#delimit ;
char year[omit]1999;
xi: reg grad_tot  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , cluster(province) noomit;
test _IyeaXhig_2003 _IyeaXhig_2004 _IyeaXhig_2005 _IyeaXhig_2006 _IyeaXhig_2007 _IyeaXhig_2008 _IyeaXhig_2009;

*********************************************************;
*Graduation results (2003 and 2010 changes);
*********************************************************;
#delimit ;
foreach var of varlist grad_tot1 {;
	
	if "`var'"=="grad_tot1" {; local t="3"; };
	if "`var'"=="grad_tot1" {; local v="ylabel(-1(0.5)1) ymtick(-1(.25)1)"; };
	if "`var'"=="grad_tot1" {; local w="1998"; };
	if "`var'"=="grad_tot1" {; local c="Percentage Points"; };
	
	
	*POOLED;
	xi: reg `var' post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1 yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
		yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode $controls_yr if year>=`w'&year<=2013, cluster(province); 
	
	estimates store spec`t', title("`var'");
	su `var' if e(sample)&year>=1998&year<2003&high1==1;
	scalar dep_mean=r(mean);
	estadd scalar dep_mean=dep_mean;

	preserve;
	gen slope1991=-11*_b[ttrend_three_high1];
	forvalues x=1992/2001 {;
		local i=`x'-2002;
		gen slope`x'=`i'*_b[ttrend_three_high1];
	};
	
	
	gen slope2002=0*_b[ttrend_three_high1];
	
	forvalues x=2003/2009 {;
		local i=`x'-2002;
		local j=`x'-2003;

		gen slope`x'=`i'*_b[ttrend_three_high1]+_b[post2003_high]+`j'*_b[post2003_trend_three];
	};

	gen slope2010=8*_b[ttrend_three_high1]+_b[post2003_high]+7*_b[post2003_trend_three]+0*_b[post2010_trend_three]+_b[post2010_high];


	forvalues x=2011/2013 {;
		local i=`x'-2002;
		local j=`x'-2009;
		local k=`x'-2003;
		local m=`x'-2010;

		gen slope`x'=`i'*_b[ttrend_three_high1]+_b[post2003_high]+_b[post2010_high]+`k'*_b[post2003_trend_three]+`m'*_b[post2010_trend_three];

	};
	
	*EVENT STUDY;
	char year[omit]2002;
	xi: reg `var'  i.year|high1 i.year i.provcode $controls_yr if year>=1998&year<=2013, cluster(province) noomit;
	estimates store event`t', title("'var'");
	test _IyeaXhig_1998 _IyeaXhig_2000 _IyeaXhig_2001; 		
	scalar pretrend=r(p);
	estadd scalar pretrend=pretrend;
	sum `var' if high1==1 & year==2000;
	local mean=`r(mean)';
				
	foreach y of numlist 1991(1)2001 2003(1)2013 {;
			gen b_`y' = _b[_IyeaXhig_`y'];
			gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
			gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
	};

		gen b_2002=0;
		
		keep b_* upper_* lower_* slope*;
		
		
		collapse b_* upper_* lower_* slope*; 
		
		gen temp=1;
		reshape long b_ upper_ lower_ slope, i(temp) j(year); 
		drop temp;
		
		drop if year<`w';
		
		twoway (line b_ year, lcolor(black) lpattern(solid))
				(line upper_  year, lcolor(black) lpattern(dot))
				(line lower_ year, lcolor(black) lpattern(dot))
				(line slope year, lcolor(black) lpattern(dash)),

				legend(off)
				xtitle("Year") 
				yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle(`c')
				plotregion(fcolor(white)) graphregion(fcolor(white))
				xline(2000 2007, lpattern(solid) lcolor(gs14)) 
				xlabel(1990(5)2015) ymtick(1990(5)2015)
				`v';
				
		graph export "${figures}Main Figures/EventStudy_`var'.pdf", replace;

		
restore;	
};


********************************************************************************;
*Output Table 1;
*POOLED EVENT STUDY ESTIMATES;
********************************************************************************;

	estout spec1 spec2 spec4 spec5 spec6 using "${output}Table1.txt", 
		replace 
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean  
			, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))
		keep(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
		order(post2000_high post2000_trend post2007_high post2007_trend ttrend_high1)
	label;
	
	estout spec3 using "${output}Table1.txt", 
		append
		cells(b(star fmt(%9.3f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean 
			, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable"))	
		keep(post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1)
		order(post2003_high post2003_trend_three post2010_high post2010_trend_three ttrend_three_high1)
		label;

estimates drop _all;
********************************************************************************;
*TABLE 2: Effects on Non-Nursing Enrollment and Graduation;
********************************************************************************;

foreach var of varlist enroll_tot0 enroll_tot  {;
		
		if "`var'"=="enroll_tot0" {; local c="1"; };
		if "`var'"=="enroll_tot" {; local c="2"; };

		xi: reg `var' post2000_high post2007_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			$controls_yr if year>=1991&year<=2013, cluster(province); 
		estimates store spec`c', title(`var');
		
};

foreach var of varlist grad_tot0 grad_tot {;
		
		if "`var'"=="grad_tot0" {; local c="3"; };
		if "`var'"=="grad_tot" {; local c="4"; };

		xi: reg `var' post2003_high post2010_high yr1991 yr1992 yr1993 yr1994 yr1995 yr1996 yr1997 yr1998 yr2000 yr2001 
			yr2002 yr2003 yr2004 yr2005 yr2006 yr2007 yr2008 yr2009 yr2010 yr2011 yr2012 yr2013 i.provcode 
			$controls_yr if year>=1998&year<=2013, cluster(province); 
		estimates store post2003`c', title(`var');
		
};

estout spec* using "${output}Table2.txt", 
	replace 
		cells(b(star fmt(%9.4f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable" "Grad Mean" "Nurse Mean"))
		keep(post2000_high post2007_high)
		order(post2000_high post2007_high)
		label;
		
estout post2003* using "${output}Table2.txt", 
	append
		cells(b(star fmt(%9.4f)) se(par)) 
		starlevels(* 0.10 ** 0.05 *** 0.01)
		stats(N r2 dep_mean, fmt(0 3 3) labels("N" "R2" "Mean Dependent Variable" "Grad Mean" "Nurse Mean"))
		keep(post2003_high post2010_high)
		order(post2003_high  post2010_high)
		label;

estimates drop _all;

********************************************************************************;
*FIGURE 3D;
********************************************************************************;
	#delimit ;
	preserve;
	
	char year[omit]1999;
		xi: reg pass_rate_grad  i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , cluster(province) noomit;
					
		foreach y of numlist 1991(1)1998 2000(1)2013 {;
				gen b_`y' = _b[_IyeaXhig_`y'];
				gen upper_`y' = b_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
				gen lower_`y' = b_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
		};

			gen b_1999=0;
			
	char year[omit]1999;
		xi: reg examinee_rate_grad i.year|high1 i.year i.provcode $controls_yr if year>=1991&year<=2013 , cluster(province) noomit;
					
		foreach y of numlist 1991(1)1998 2000(1)2013 {;
				gen eb_`y' = _b[_IyeaXhig_`y'];
				gen eupper_`y' = eb_`y' + ( _se[_IyeaXhig_`y'] * 1.96 );
				gen elower_`y' = eb_`y' - ( _se[_IyeaXhig_`y'] * 1.96 );
		};

			gen eb_1999=0;
			
			keep b_* upper_* lower_* eb_* eupper_* elower_*;
			
			collapse b_* upper_* lower_* eb_* eupper_* elower_*; 
			
			gen temp=1;
			#delimit ;
			reshape long b_ upper_ lower_ eb_ eupper_ elower_, i(temp) j(year); 
			drop temp;
						
			drop if year<1990;
			#delimit ;
			twoway (connected b_ year, lcolor(black) lpattern(solid) msymbol(smsymbol) mcolor(black))
					(line upper_  year, lcolor(black) lpattern(shortdash))
					(line lower_ year, lcolor(black) lpattern(shortdash))
					(connected eb_ year, lcolor(gs7) lpattern(solid) msymbol(triangle) mcolor(gs7))
					(line eupper_  year, lcolor(gs7) lpattern(dot))
					(line elower_ year, lcolor(gs7) lpattern(dot)),
					xtitle("Year") 
					yline(0, lstyle(shortdash_dot)) ylab(, nogrid) ytitle("Rate out of Total Population (%)")
					plotregion(fcolor(white)) graphregion(fcolor(white))
					xline(2000 2007, lpattern(solid) lcolor(gs14))
					legend(order(1 4) label(1 "Passers/Population") label(4 "Examinees/Population"));
					
			graph export "${figures}Main Figures/Figure3d.pdf", replace;

		restore;
